home *** CD-ROM | disk | FTP | other *** search
/ NeXT Education Software Sampler 1992 Fall / NeXT Education Software Sampler 1992 Fall.iso / Mathematics / Notebooks / URichMultivariateCalculus / 04 / Lab4.ma next >
Encoding:
Text File  |  1992-08-19  |  17.4 KB  |  290 lines

  1. (*^
  2.  
  3. ::[paletteColors = 128; currentKernel; 
  4.     fontset = title, inactive, noPageBreakBelow, nohscroll, preserveAspect, groupLikeTitle, center, M7, bold, L1, e8,  24, "Times"; ;
  5.     fontset = subtitle, inactive, noPageBreakBelow, nohscroll, preserveAspect, groupLikeTitle, center, M7, bold, L1, e6,  18, "Times"; ;
  6.     fontset = subsubtitle, inactive, noPageBreakBelow, nohscroll, preserveAspect, groupLikeTitle, center, M7, italic, L1, e6,  14, "Times"; ;
  7.     fontset = section, inactive, noPageBreakBelow, nohscroll, preserveAspect, groupLikeSection, grayBox, M22, bold, L1, a20,  18, "Times"; ;
  8.     fontset = subsection, inactive, noPageBreakBelow, nohscroll, preserveAspect, groupLikeSection, blackBox, M19, bold, L1, a15,  14, "Times"; ;
  9.     fontset = subsubsection, inactive, noPageBreakBelow, nohscroll, preserveAspect, groupLikeSection, whiteBox, M18, bold, L1, a12,  12, "Times"; ;
  10.     fontset = text, inactive, nohscroll, noKeepOnOnePage, preserveAspect, M7, L1,  12;
  11.     fontset = smalltext, inactive, nohscroll, noKeepOnOnePage, preserveAspect, M7, L1,  10, "Times"; ;
  12.     fontset = input, noPageBreakBelow, nowordwrap, preserveAspect, groupLikeInput, M42, N23, bold, L1,  12, "Courier"; ;
  13.     fontset = output, output, inactive, noPageBreakBelow, nowordwrap, preserveAspect, groupLikeOutput, M42, N23, L-5,  12, "Courier"; ;
  14.     fontset = message, inactive, noPageBreakBelow, nowordwrap, preserveAspect, groupLikeOutput, M42, N23, L1,  12, "Courier"; ;
  15.     fontset = print, inactive, noPageBreakBelow, nowordwrap, preserveAspect, groupLikeOutput, M42, N23, L1,  12, "Courier"; ;
  16.     fontset = info, inactive, noPageBreakBelow, nowordwrap, preserveAspect, groupLikeOutput, M42, N23, L1,  12, "Courier"; ;
  17.     fontset = postscript, PostScript, formatAsPostScript, output, inactive, noPageBreakBelow, nowordwrap, preserveAspect, groupLikeGraphics, M7, l34, w282, h287, L1,  12, "Courier"; ;
  18.     fontset = name, inactive, nohscroll, noKeepOnOnePage, preserveAspect, M7, italic, L1,  10, "Times"; ;
  19.     fontset = header, inactive, nohscroll, noKeepOnOnePage, preserveAspect, M7, L1,  12;
  20.     fontset = Left Header, nohscroll, cellOutline,  12;
  21.     fontset = footer, inactive, nohscroll, noKeepOnOnePage, preserveAspect, center, M7, L1,  12;
  22.     fontset = Left Footer, cellOutline, blackBox,  12;
  23.     fontset = help, inactive, nohscroll, noKeepOnOnePage, preserveAspect, M7, L1,  10, "Times"; ;
  24.     fontset = clipboard, inactive, nohscroll, noKeepOnOnePage, preserveAspect, M7, L1,  12;
  25.     fontset = completions, inactive, nohscroll, noKeepOnOnePage, preserveAspect, M7, L1,  12, "Courier"; ;
  26.     fontset = special1, inactive, nohscroll, noKeepOnOnePage, preserveAspect, M7, L1,  12;
  27.     fontset = special2, inactive, nohscroll, noKeepOnOnePage, preserveAspect, M7, L1,  12;
  28.     fontset = special3, inactive, nohscroll, noKeepOnOnePage, preserveAspect, M7, L1,  12;
  29.     fontset = special4, inactive, nohscroll, noKeepOnOnePage, preserveAspect, M7, L1,  12;
  30.     fontset = special5, inactive, nohscroll, noKeepOnOnePage, preserveAspect, M7, L1,  12;
  31.     next21StandardFontEncoding; ]
  32. :[font = title; inactive; Cclosed; preserveAspect; startGroup; ]
  33. Lab 4: Derivatives
  34. :[font = text; inactive; preserveAspect; ]
  35. Mathematica handles derivatives of functions of several variables the same way it handles derivatives of single-variable functions.  Consequently, most of the problems that we solve using partial derivatives can be done by Mathematica.  This lab illustrates some of those methods.
  36. ;[s]
  37. 4:0,0;11,1;223,2;234,3;281,-1;
  38. 4:1,10,8,Times,2,12,0,0,0;1,11,8,Times,0,12,0,0,0;1,10,8,Times,2,12,0,0,0;1,11,8,Times,0,12,0,0,0;
  39. :[font = section; inactive; Cclosed; preserveAspect; startGroup; ]
  40. Partial Derivatives
  41. :[font = text; inactive; preserveAspect; ]
  42. A partial derivative is simply a derivative of a function of several variables, where the derivative is taken while all but one of the variables are held constant.  Mathematica's notation for partial derivatives is the same as that for ordinary derivatives.
  43. ;[s]
  44. 3:0,0;165,1;176,2;258,-1;
  45. 3:1,11,8,Times,0,12,0,0,0;1,10,8,Times,2,12,0,0,0;1,11,8,Times,0,12,0,0,0;
  46. :[font = subsection; inactive; Cclosed; preserveAspect; startGroup; ]
  47. Example
  48. :[font = text; inactive; Cclosed; preserveAspect; startGroup; ]
  49. This example is Example 2 on page 646 of Stein:
  50. :[font = input; preserveAspect; ]
  51. f[x_,y_] := x^2y^3 + E^(x^2y)
  52. :[font = text; inactive; preserveAspect; ]
  53. It's always a good idea to check your definitions:
  54. :[font = input; preserveAspect; endGroup; ]
  55. f[x,y]
  56. :[font = text; inactive; Cclosed; preserveAspect; startGroup; ]
  57. Now, the partial derivative of f with respect to x (i.e. holding y constant) is:
  58. ;[s]
  59. 7:0,0;31,1;32,2;49,3;50,4;65,5;66,6;81,-1;
  60. 7:1,11,8,Times,0,12,0,0,0;1,10,8,Times,2,12,0,0,0;1,11,8,Times,0,12,0,0,0;1,10,8,Times,2,12,0,0,0;1,11,8,Times,0,12,0,0,0;1,10,8,Times,2,12,0,0,0;1,11,8,Times,0,12,0,0,0;
  61. :[font = input; preserveAspect; endGroup; ]
  62. D[f[x,y],x]
  63. :[font = text; inactive; Cclosed; preserveAspect; startGroup; ]
  64. And the partial with respect to y is:
  65. ;[s]
  66. 3:0,0;32,1;33,2;38,-1;
  67. 3:1,11,8,Times,0,12,0,0,0;1,10,8,Times,2,12,0,0,0;1,11,8,Times,0,12,0,0,0;
  68. :[font = input; preserveAspect; endGroup; endGroup; ]
  69. D[f[x,y],y]
  70. :[font = subsection; inactive; Cclosed; preserveAspect; startGroup; ]
  71. Exercises
  72. :[font = text; inactive; preserveAspect; ]
  73. 1. Exercise 3 on page 648 of Stein.
  74. :[font = text; inactive; preserveAspect; endGroup; endGroup; ]
  75. 2. Exercise 5 on page 648 of Stein.
  76. :[font = section; inactive; Cclosed; pageBreak; preserveAspect; startGroup; ]
  77. The Gradient Function
  78. :[font = text; inactive; preserveAspect; ]
  79. The gradient of a function of several variables is simply the vector-valued function whose components are the partial derivatives of the given function.  Recall that Mathematica uses braces { } to denote vectors.
  80. ;[s]
  81. 5:0,0;166,1;177,2;189,3;194,4;213,-1;
  82. 5:1,11,8,Times,0,12,0,0,0;1,10,8,Times,2,12,0,0,0;1,11,8,Times,0,12,0,0,0;1,10,8,Courier,1,12,0,0,0;1,11,8,Times,0,12,0,0,0;
  83. :[font = subsection; inactive; Cclosed; preserveAspect; startGroup; ]
  84. Example
  85. :[font = text; inactive; Cclosed; preserveAspect; startGroup; ]
  86. We will define the grad function as a function of  f, x, and y.  This way, we can change the definition of f without having to redefine the grad symbol.
  87. ;[s]
  88. 13:0,0;19,1;23,2;51,3;52,4;54,5;55,6;61,7;62,8;107,9;108,10;140,11;144,12;153,-1;
  89. 13:1,11,8,Times,0,12,0,0,0;1,10,8,Times,2,12,0,0,0;1,11,8,Times,0,12,0,0,0;1,10,8,Times,2,12,0,0,0;1,11,8,Times,0,12,0,0,0;1,10,8,Times,2,12,0,0,0;1,11,8,Times,0,12,0,0,0;1,10,8,Times,2,12,0,0,0;1,11,8,Times,0,12,0,0,0;1,10,8,Times,2,12,0,0,0;1,11,8,Times,0,12,0,0,0;1,10,8,Times,2,12,0,0,0;1,11,8,Times,0,12,0,0,0;
  90. :[font = input; preserveAspect; ]
  91. Clear[f]
  92. :[font = text; inactive; preserveAspect; ]
  93. We have to "undefine" f first so that it can act as a variable in the grad definition:
  94. ;[s]
  95. 5:0,0;22,1;24,2;69,3;75,4;87,-1;
  96. 5:1,11,8,Times,0,12,0,0,0;1,10,8,Times,2,12,0,0,0;1,11,8,Times,0,12,0,0,0;1,10,8,Courier,1,12,0,0,0;1,11,8,Times,0,12,0,0,0;
  97. :[font = input; preserveAspect; ]
  98. grad[f_,x_,y_] := {D[f[x,y],x],D[f[x,y],y]}
  99. :[font = text; inactive; preserveAspect; ]
  100. Here, were are assuming that f will always be a function of two variables.
  101. ;[s]
  102. 3:0,0;28,1;31,2;75,-1;
  103. 3:1,11,8,Times,0,12,0,0,0;1,10,8,Courier,1,12,0,0,0;1,11,8,Times,0,12,0,0,0;
  104. :[font = input; preserveAspect; ]
  105. grad[f,x,y]
  106. :[font = text; inactive; preserveAspect; endGroup; ]
  107. Notice that Mathematica has another way of denoting partial derivatives.
  108. ;[s]
  109. 3:0,0;12,1;23,2;73,-1;
  110. 3:1,11,8,Times,0,12,0,0,0;1,10,8,Times,2,12,0,0,0;1,11,8,Times,0,12,0,0,0;
  111. :[font = text; inactive; Cclosed; preserveAspect; startGroup; ]
  112. Here is a simple example:
  113. :[font = input; preserveAspect; ]
  114. f[x_,y_] := x^2 y^3
  115. :[font = input; preserveAspect; ]
  116. f[x,y]
  117. :[font = input; preserveAspect; endGroup; endGroup; ]
  118. grad[f,x,y]
  119. :[font = subsection; inactive; Cclosed; preserveAspect; startGroup; ]
  120. Exercise
  121. :[font = text; inactive; preserveAspect; endGroup; endGroup; ]
  122. Define the gradient for the function x / Sqrt[x^2 + y^2].
  123. ;[s]
  124. 7:0,0;37,1;38,2;46,3;47,4;52,5;53,6;58,-1;
  125. 7:1,11,8,Times,0,12,0,0,0;1,10,8,Times,2,12,0,0,0;1,11,8,Times,0,12,0,0,0;1,10,8,Times,2,12,0,0,0;1,11,8,Times,0,12,0,0,0;1,10,8,Times,2,12,0,0,0;1,11,8,Times,0,12,0,0,0;
  126. :[font = section; inactive; Cclosed; preserveAspect; startGroup; ]
  127. Critical Points
  128. :[font = text; inactive; preserveAspect; ]
  129. Recall that a critical point of a function is a point where the function's derivative changes sign (positive to negative, or negative to positive).  If the derivative is continuous at the critical point, then it must equal zero there. 
  130. :[font = text; inactive; preserveAspect; ]
  131. Critical points are where extrema (maxima and minima) occur.  So we can find the extreme values of a function by locating its critical points.  For functions of several variables, this means setting all the partial derivatives equal to zero.  But that's equivalent to setting the gradient vector equal to zero.
  132. :[font = subsection; inactive; Cclosed; pageBreak; preserveAspect; startGroup; ]
  133. Example
  134. :[font = text; inactive; Cclosed; preserveAspect; startGroup; ]
  135. Here's a simple function that has two critical points:
  136. :[font = input; preserveAspect; endGroup; ]
  137. f[x_,y_] := 3*x*y - x^3 - y^3
  138. :[font = text; inactive; Cclosed; preserveAspect; startGroup; ]
  139. We ask Mathematica to set the gradient equal to zero and solve:
  140. ;[s]
  141. 3:0,0;7,1;18,2;64,-1;
  142. 3:1,11,8,Times,0,12,0,0,0;1,10,8,Times,2,12,0,0,0;1,11,8,Times,0,12,0,0,0;
  143. :[font = input; preserveAspect; ]
  144. Solve[grad[f,x,y]==0,{x,y}]
  145. :[font = text; inactive; preserveAspect; ]
  146. Note that the symbol 0 in the Input statement actually represents the vector (0,0).
  147. ;[s]
  148. 4:0,0;20,1;23,2;65,3;66,-1;
  149. 4:1,11,8,Times,0,12,0,0,0;1,10,8,Courier,1,12,0,0,0;1,11,8,Times,0,12,0,0,0;1,11,8,Times,0,12,0,0,0;
  150. :[font = text; inactive; preserveAspect; endGroup; ]
  151. The answer is a list of four points.  The second and third points involve the imaginary constant I (the square root of -1), so these can be discarded.  That leaves two points: (1,1) and (0,0).
  152. ;[s]
  153. 3:0,0;96,1;99,2;193,-1;
  154. 3:1,11,8,Times,0,12,0,0,0;1,10,8,Courier,1,12,0,0,0;1,11,8,Times,0,12,0,0,0;
  155. :[font = text; inactive; Cclosed; preserveAspect; startGroup; ]
  156. Consider the point (0,0).
  157. :[font = text; inactive; preserveAspect; ]
  158. First check the gradient at the point (0,0) to be sure that it is the zero vector
  159. :[font = input; preserveAspect; ]
  160. grad[f,x,y] /. {x -> 0, y -> 0}
  161. :[font = text; inactive; preserveAspect; endGroup; ]
  162. This tells us that both partial derivatives are equal to zero at the point (0,0).
  163. :[font = text; inactive; Cclosed; preserveAspect; startGroup; ]
  164. Now let's take a look  at the graph of f near the point (0,0).
  165. ;[s]
  166. 3:0,0;39,1;40,2;63,-1;
  167. 3:1,11,8,Times,0,12,0,0,0;1,10,8,Times,2,12,0,0,0;1,11,8,Times,0,12,0,0,0;
  168. :[font = input; preserveAspect; ]
  169. Plot3D[ f[x,y], {x,-0.2,0.2}, {y,-0.2,0.2},
  170.         PlotPoints -> 32 ];
  171. :[font = text; inactive; preserveAspect; ]
  172. The two perpendicular lines on this surface that contain the point (0,0,0) are both horizontal.  This verifies that the partial derivatives (which equal the slopes of those two lines) are both zero.
  173. :[font = text; inactive; preserveAspect; endGroup; ]
  174. The graph also shows that the function does not have an extreme value at the critical point (0,0).  That point is a "saddle point" on the surface: the graph goes up in some directions and down in others.
  175. :[font = text; inactive; Cclosed; preserveAspect; startGroup; ]
  176. We can also use a contour plot to verify that this critical point is a saddle point:
  177. :[font = input; preserveAspect; ]
  178. ContourPlot[ f[x,y], {x,-0.2,0.2}, {y,-0.2,0.2},
  179.              PlotPoints -> 32 ];
  180. :[font = text; inactive; preserveAspect; endGroup; ]
  181. The level curves near the critical point curve out away from the critical point.  That is the characteristic "signature" of a saddle point.
  182. :[font = text; inactive; Cclosed; preserveAspect; startGroup; ]
  183. Consider the point (1,1).
  184. :[font = text; inactive; preserveAspect; ]
  185. Again, check the gradient at the point (0,0) to be sure that it is the zero vector
  186. :[font = input; preserveAspect; endGroup; ]
  187. grad[f,x,y] /. {x -> 1, y -> 1}
  188. :[font = text; inactive; Cclosed; pageBreak; preserveAspect; startGroup; ]
  189. Now examine the graph of f near the point (1,1):
  190. ;[s]
  191. 3:0,0;25,1;27,2;49,-1;
  192. 3:1,11,8,Times,0,12,0,0,0;1,10,8,Times,2,12,0,0,0;1,11,8,Times,0,12,0,0,0;
  193. :[font = input; preserveAspect; ]
  194. Plot3D[ f[x,y], {x,0.8,1.2}, {y,0.8,1.2},
  195.         PlotPoints -> 32 ];
  196. :[font = text; inactive; preserveAspect; endGroup; ]
  197. This indicates that the function decreases as one moves away from the point in any direction.  That suggests that the function has a relative maximum at (1,1).
  198. :[font = text; inactive; Cclosed; preserveAspect; startGroup; ]
  199. Again, a contour plot will shed more light:
  200. :[font = input; preserveAspect; ]
  201. ContourPlot[ f[x,y], {x,0.8,1.2}, {y,0.8,1.2},
  202.              PlotPoints -> 32 ];
  203. :[font = text; inactive; preserveAspect; endGroup; endGroup; ]
  204. All the level curves near the critical point are closed curves around the point.  This verifies that the point is an extremum (i.e. either a maximum or a minimum).
  205. :[font = subsection; inactive; Cclosed; preserveAspect; startGroup; ]
  206. Exercise
  207. :[font = text; inactive; preserveAspect; endGroup; endGroup; ]
  208. Find and classify the critical points for the function  x^3 + 6*x*y - y^3 .
  209. :[font = section; inactive; Cclosed; preserveAspect; startGroup; ]
  210. Higher Derivatives
  211. :[font = text; inactive; preserveAspect; ]
  212. A function of two variables has two first derivatives, four second derivatives, eight third derivatives, etc.  Mathematica uses consistent notation for these partial derivatives.
  213. ;[s]
  214. 3:0,0;111,1;122,2;179,-1;
  215. 3:1,11,8,Times,0,12,0,0,0;1,10,8,Times,2,12,0,0,0;1,11,8,Times,0,12,0,0,0;
  216. :[font = subsection; inactive; Cclosed; preserveAspect; startGroup; ]
  217. Example
  218. :[font = text; inactive; Cclosed; preserveAspect; startGroup; ]
  219. Here's  the same example we used in the first section:
  220. :[font = input; preserveAspect; endGroup; ]
  221. f[x_,y_] := x^2y^3 + E^(x^2y)
  222. :[font = text; inactive; Cclosed; preserveAspect; startGroup; ]
  223. It's four second partials are:
  224. :[font = input; preserveAspect; ]
  225. D[f[x,y],x,x]
  226. :[font = input; preserveAspect; ]
  227. D[f[x,y],x,y]
  228. :[font = input; preserveAspect; ]
  229. D[f[x,y],y,x]
  230. :[font = input; preserveAspect; endGroup; endGroup; ]
  231. D[f[x,y],y,y]
  232. :[font = subsection; inactive; Cclosed; preserveAspect; startGroup; ]
  233. Exercise
  234. :[font = text; inactive; preserveAspect; endGroup; endGroup; ]
  235. Find the four second partial derivatives of the function  x^3 + 6*x*y - y^3 , and verify that D[f [x,y], x, y] =  D[f [x,y], y, x].
  236. :[font = section; inactive; Cclosed; pageBreak; preserveAspect; startGroup; ]
  237. The Second Derivative Test
  238. :[font = text; inactive; Cclosed; preserveAspect; startGroup; ]
  239. For a function of a single variable, the Second Derivative Test says that, at a critical point, the function has a maximum if the second derivative is negative and its has a minimum if the second derivative is positive.
  240. :[font = text; inactive; preserveAspect; endGroup; ]
  241. For a function of two variables, the Second Derivative Test works the same way, but only under the further condition that the discriminant of the function is positive.  If the discriminant is negative, then the critical point is a saddle point.
  242. :[font = subsection; inactive; Cclosed; preserveAspect; startGroup; ]
  243. Example
  244. :[font = text; inactive; Cclosed; preserveAspect; startGroup; ]
  245. First, we'll define the discriminant to ba a function of f, x, and y:
  246. ;[s]
  247. 7:0,0;57,1;58,2;60,3;61,4;67,5;68,6;70,-1;
  248. 7:1,11,8,Times,0,12,0,0,0;1,10,8,Times,2,12,0,0,0;1,11,8,Times,0,12,0,0,0;1,10,8,Times,2,12,0,0,0;1,11,8,Times,0,12,0,0,0;1,10,8,Times,2,12,0,0,0;1,11,8,Times,0,12,0,0,0;
  249. :[font = input; preserveAspect; ]
  250. Clear[f]
  251. :[font = input; preserveAspect; ]
  252. d2[f_,x_,y_] := D[f[x,y],x,x]D[f[x,y],y,y]- D[f[x,y],x,y]^2
  253. :[font = text; inactive; preserveAspect; ]
  254. (Recall that this expression is the determinant of the matrix of second partials.)
  255. :[font = input; preserveAspect; endGroup; ]
  256. d2[f,x,y]
  257. :[font = text; inactive; Cclosed; preserveAspect; startGroup; ]
  258. Consider again the example from the section on Critical Points:
  259. :[font = input; preserveAspect; ]
  260. f[x_,y_] := 3*x*y - x^3 - y^3
  261. :[font = text; inactive; preserveAspect; ]
  262. Its discriminant function is:
  263. :[font = input; preserveAspect; ]
  264. d2[f,x,y]
  265. :[font = text; inactive; preserveAspect; ]
  266. Its value at the critical point (0,0) is:
  267. :[font = input; preserveAspect; ]
  268. d2[f,x,y] /. {x->0,y->0}
  269. :[font = text; inactive; preserveAspect; endGroup; ]
  270. The negative discriminant tells us that the critical point is a saddle point, just as the contour plot suggested.
  271. :[font = text; inactive; Cclosed; preserveAspect; startGroup; ]
  272. The value of the discriminant at the critical point (1,1) is:
  273. :[font = input; preserveAspect; ]
  274. d2[f,x,y] /. {x->1,y->1}
  275. :[font = text; inactive; preserveAspect; ]
  276. The positive discriminant tells us that the critical point is an extreme point.
  277. :[font = text; inactive; preserveAspect; ]
  278. Now, the value of the second partial D[f [x,y], x, x] at this point will tell us whether the extremum is a minimum or a maximum.
  279. ;[s]
  280. 3:0,0;36,1;54,2;129,-1;
  281. 3:1,11,8,Times,0,12,0,0,0;1,10,8,Courier,1,12,0,0,0;1,11,8,Times,0,12,0,0,0;
  282. :[font = input; preserveAspect; ]
  283. D[f[x,y],x,x] /. {x->1,y->1}
  284. :[font = text; inactive; preserveAspect; endGroup; endGroup; ]
  285. Just as with functions of a single variable, a negative second derviative tells us that the function has a relative maximum at that critical point.
  286. :[font = subsection; inactive; Cclosed; pageBreak; preserveAspect; startGroup; ]
  287. Exercise
  288. :[font = text; inactive; preserveAspect; endGroup; endGroup; endGroup; ]
  289. Find  the critical points for the function  4x^2*y + 3x*y^2 - 12x*y, and then use the Second Derivative Test  to classify them (minimum, maximum, or saddle point).
  290. ^*)